package com.irain.pp.tool.mybatis.pagehelper;

import com.github.pagehelper.dialect.AbstractHelperDialect;
import com.github.pagehelper.page.PageAutoDialect;

import java.lang.reflect.Field;
import java.util.Map;

/**
 * @author WangYanPeng
 * @date 2017/10/19 19:55
 */
public class PageHelperUtils {

    @SuppressWarnings("unchecked")
    public static void replaceSqlDialect(String key,Class<? extends AbstractHelperDialect> clazz)
            throws NoSuchFieldException,IllegalAccessException{
        Field dialectAliasMapFiled = PageAutoDialect.class.getDeclaredField("dialectAliasMap");
        dialectAliasMapFiled.setAccessible(true);
        Map<String, Class<?>> map = (Map<String, Class<?>>) dialectAliasMapFiled.get(null);
        map.put(key, clazz);
    }
}
